﻿using System;
using System.Data;
using System.Drawing;
using System.Web.UI;
using System.Web.UI.WebControls;
using Utils;
using BLL;
namespace UI.ModMini
{
    public partial class CredentialList : System.Web.UI.Page
    {
        MiniBiz miniBiz = new MiniBiz();
        DateTime thisTime = System.DateTime.Now;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                btnAdd.Attributes.Add("onclick", "javascript:ShowLink('CredentialAdd.aspx',800,550);");
                 BondData("");

            }
        }
        private void BondData(string serWord)
        {
            DataTable dt = miniBiz.GetCredLists(serWord);

            if (dt.Rows.Count > 0)
            {
                lbAmount.Text = "合计:    " + dt.Rows.Count;
            }
            else
            {
                lbAmount.Text = "";
            }
            gvList.DataSource = dt;
            gvList.DataBind();

        }
        protected void btnEmSearch_Click(object sender, EventArgs e)
        {
             BondData(txtSerWord.Text.Trim());
        }

        protected void btnExcel_Click(object sender, EventArgs e)
        {
            ExcelUtility.ExportDsToXls(this, miniBiz.GetCredLists(txtSerWord.Text.Trim()), "CredList.xls");
        }

        protected void gvList_RowDataBound(object sender, GridViewRowEventArgs e)
        {

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#F3F8F8'");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
                string eTime = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "Etime"));
                string nextTime = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "NextTime"));
                if (RegexRule.IsDate(eTime))
                {
                    if (StringUtility.GetDiffDays(thisTime, DateTime.Parse(eTime)) < 30)
                    e.Row.BackColor = Color.Red;                                       
                }
                if (RegexRule.IsDate(nextTime))
                {
                    if (StringUtility.GetDiffDays(thisTime, DateTime.Parse(nextTime)) < 30)
                        e.Row.BackColor = Color.BlueViolet;
                }
            }
        }
    }
}